package service

import (
	"duoke/model"
	"duoke/tables"
	"duoke/utils/orm"
	"errors"
	"github.com/gin-gonic/gin"
)

var CouponList = new(couponListService)

type couponListService struct{}

func (s *couponListService) List(c *gin.Context, where string, req *model.ReqList) error {
	var m tables.YogaOrder
	req.PageSize = 1000
	// 计算数据总量
	count, err := orm.Db.Where(where).Count()
	if err != nil || count == 0 {
		return errors.New("用户订单数据错误")
	}
	for {
		offset := (req.PageNo - 1) * req.PageSize
		if int64(offset) >= 0 && int64(offset) < count {
			err := orm.Db.Where(where).Limit(req.PageSize, offset).Find(&m)
			if err != nil {
				return err
			}
		}
	}

}
